package com.ourygo.fileselect.util;

import android.app.Activity;
import android.content.Context;
import android.os.Environment;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.ourygo.fileselect.OurygoApplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;

public class Utils
{	
	//ygomobile默认路径
    public static final String PATH_MOBILE= Environment.getExternalStorageDirectory().toString() + "/Android/data/cn.garymb.ygomobile/files/ygocore/";
    public static final String PATH_YGO_OY= Environment.getExternalStorageDirectory().toString() + "/ygocore/";
	//根目录
	public static final String PATH_GEN=Environment.getExternalStorageDirectory().toString()+"/";
	//我们的游戏王默认路径
	public static final String PATH_OURYGO=Environment.getExternalStorageDirectory().toString()+"/"+"ourygo/";
	
	public static final RequestOptions glideOption =RequestOptions
	.diskCacheStrategyOf(DiskCacheStrategy.RESOURCE)
	.skipMemoryCache(true);
	//.placeholder(R.drawable.image_jiazai);
	
	
	public static void initToolbar(final AppCompatActivity activity, Toolbar toolbar, String s, boolean isBack){
		toolbar.setTitle(s);
		activity.setSupportActionBar(toolbar);

		if(isBack){
			toolbar.setNavigationIcon(androidx.appcompat.R.drawable.abc_ic_ab_back_material);//  context.getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
			toolbar.setNavigationOnClickListener(new View.OnClickListener(){

					@Override
					public void onClick(View p1)
					{
						activity.finish();
						// TODO: Implement this method
					}
				});
		}
	}
	
	public static String s(Context context, int string){
		return context.getResources().getString(string);
	}

	public static int c(Context context,int color){	
		return ContextCompat.getColor(context,color);
	}
	
	//显示虚拟键盘
	public static void ShowKeyboard(View v)
	{
		v.requestFocus();
		InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		// imm.showSoftInput(v,InputMethodManager.SHOW_FORCED);    

		imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
	}

	//关闭输入法
	public static void closeKeyboard(Context context){
		InputMethodManager inputMethodManager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
		inputMethodManager.hideSoftInputFromWindow(((Activity)context).getCurrentFocus().getWindowToken()
												   ,InputMethodManager.HIDE_NOT_ALWAYS);
	}
	
	public static void setImage(Context context, ImageView iv, int id){
		Glide.with(context).load(id).apply(glideOption).into(iv);
	}
	public static void setImage(Context context,ImageView iv,String path){
		Glide.with(context).load(path).apply(glideOption).into(iv);
	}
	
	public static void clearImageCache(Context context){
		Glide.get(context).clearDiskCache();
	}

	public static void show(String message){
		show(OurygoApplication.getContext(),message);
	}

	public static void show(Context context,String message){
		Toast.makeText(context,message,Toast.LENGTH_SHORT).show();
	}
	
}
